package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.resource.entity.QueryPageBean;
import com.itheima.health.service.CheckItemService;
import com.itheima.mapper.CheckitemMapper;
import com.itheima.pojo.CheckItem;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CheckitemServiceImpl extends ServiceImpl<CheckitemMapper, CheckItem>  implements CheckItemService {
    @Override
    public Map findPageByCondition(QueryPageBean queryPageBean) {
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<CheckItem>();
        String queryString = queryPageBean.getQueryString();//条件
        queryWrapper.like("name",queryString==null?"":queryString);
        queryWrapper.eq("is_delete",0);//  有效数据
        //  select  * from xxx where name like  xx  and  is_delete = 0


        //分页请求参数条件获取page对象
        Page<CheckItem> page = page(new Page<CheckItem>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()),queryWrapper);
        //获取每页请求的数据封装到list集合中给实体类
        List<CheckItem> checkItemList = page.getRecords();
        //获取总记录数将其封装到map集合中
        long total = page.getTotal();
        HashMap map = new HashMap();
        map.put("list",checkItemList);
        map.put("total",total);
        return map;
    }

    @Override
    public List<CheckItem> findAll() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_delete",0);//  有效数据
        List<CheckItem> list = list(queryWrapper);
        return list;
    }

    @Override
    public List<Integer> findCheckItemIdsByGroupId(int id) {
        return baseMapper.findCheckItemIdsByGroupId(id);
    }

}
